function plot_gaussian3d(mu=[0 0], sigma=[1 0.7 ; 0.7 1], range=5, step_size=0.1)

subplot_amount = 2;

% fix the label-title overlap in suplot
graphics_toolkit fltk 
close all 


% fix the label-title overlap in suplot
effective_range = (range*2)/step_size;

[x_vec, y_vec] = meshgrid(linspace(-range,range,effective_range),linspace(-range,range,effective_range)); 
z = zeros(effective_range, effective_range);

% filling the z matrix
for x = 1:effective_range
    for y = 1:effective_range
        x_value = x_vec(1, x);
        z(x, y) = mvnpdf([x_value, y_vec(y, 1)], mu, sigma);
    end
end

% plotting contour
%axis ("auto"); 
subplot(2, 1, 1)

mesh(x_vec, y_vec, z)

zlabel('z')
xlabel('x');
ylabel('y');
title('Gaussian 3D plot')


% calculating x1 for different values of x2
x2 = -3:1:3;
z3 = zeros(effective_range, size(x2, 2));

for i = 1:size(x2, 2)
    for x = 1:effective_range
        x_value = x_vec(1, x);
        z3(x, i) = mvnpdf([x_value, x2(i)], mu, sigma);
    end
end

% plotting distribution
subplot(2, 1, 2)

colors = ['b', 'r', 'g', 'k', 'm', 'c', 'y'];

for i = 1:size(x2, 2)
    hold on;
    plot(z3(:, i), colors(8-i))
end

legend('-3', '-2', '-1', '0', '1', '2', '3');

%axis ("auto"); 
xlabel('x');
ylabel('y');
title('Distribution over x1 with different values for x2')


% printin' to file!
print ('-dpdf','gaussian3d.pdf') 

